package com.douqu.game.merge.queue;

import java.util.Random;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @Author: Bean
 * @Description:
 * @Date: 2018-02-08 4:39
 */
public class RouteTest implements Runnable{

    private Random random = new Random(47);

    private int count = 0;

    LinkedBlockingQueue<RouteObject> queue;

    public RouteTest(LinkedBlockingQueue<RouteObject> queue)
    {
        this.queue = queue;
    }


    @Override
    public void run() {
        try {
            while(!Thread.interrupted()) {
                TimeUnit.MILLISECONDS.sleep(300 + random.nextInt(500));
                //生产一片吐司，这些吐司是有序的
                RouteObject routeObject = new RouteObject("123"+random.nextInt(100),1,1,2);
                //放到toastQueue中
                queue.put(routeObject);
            }
        } catch (InterruptedException e) {
            System.out.println("Toaster interrupted.");
        }
        System.out.println("Toaster off.");
    }
}
